<!DOCTYPE html>
<html>
<head>
    {include file="public/header" /}
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <form class="layui-form layui-form-pane" action="">
            <!--<fieldset class="table-search-fieldset">-->
                <!--<legend>搜索信息</legend>-->
                <div style="margin: 10px 10px 10px 10px">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">名称</label>
                            <div class="layui-input-inline">
                                <input type="text" name="title" placeholder="请输入名称" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <select name="" id="" lay-filter="status">
                                <option value="" selected>全部</option>
                                <option value="1">收益中</option>
                                <option value="2">待出售</option>
                                <option value="3">出售中</option>
                                <option value="4">待交租</option>
                                <option value="5">已冻结</option>
                                <option value="7">待确认</option>
                                <option value="8">等待付款</option>
                            </select>
                        </div>
                        <div class="layui-inline" style="display: none">
                            <button type="submit" class="layui-btn layui-btn-primary" lay-submit lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索</button>
                        </div>
                    </div>
                </div>
            <!--</fieldset>-->
        </form>
        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">
                <button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-event="add">赠送</button>
                <button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-event="warelist">仓库生意列表</button>
            </div>
        </script>
        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>
        <script type="text/html" id="currentTableBar">
            {{#  if(d.id !=null&&d.status === 7){ }}
                <a class="layui-btn layui-btn-xs" lay-event="confimTrade">确认交易</a>
            {{#  } else { }}
                {{#  if(d.id !=null){ }}
                <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete">删除</a>
                {{#  } else { }}

                {{#  } }}

            {{#  } }}

        </script>
        <input type="hidden" id="memberCode">
    </div>
</div>
{include file="public/footer" /}
<script type="text/html" id="statusTpl">
    {{#  if(d.open_status === 1){ }}
        {{#  if(d.id !=null){ }}
            {{#  if(d.status === 1){ }}
            <span>收益中</span>
            {{# }else if(d.status === 2||d.status === 9){ }}
            <span>待出售</span>
            {{# }else if(d.status === 3){ }}
            <span>出售中</span>
            {{# }else if(d.status === 4){ }}
            <span>待交租</span>
            {{# }else if(d.status === 5){ }}
            <span>已冻结</span>
            {{# }else if(d.status === 7){ }}
            <span>待确认</span>
            {{# }else if(d.status === 8){ }}
            <span>等待付款</span>
           {{#  } else { }}
            <span>已冻结</span>
            {{#  } }}
        {{#  } else { }}
        <span>可收购</span>
        {{#  } }}
    {{# }else if(d.open_status === 0){ }}
        <span>未开启</span>
    {{# }else if(d.open_status === 2){ }}
        <span>待开启</span>
    {{# }else if(d.open_status === 3){ }}
        <span>打扫中</span>
    {{# }else if(d.open_status === 4){ }}
        <span>匹配中</span>
    {{# }else if(d.open_status === 5){ }}
        <span>匹配成功</span>
    {{# }else if(d.open_status === 6){ }}
        <span>待买家确认</span>
    {{# }else if(d.open_status === 7){ }}
        <span>待付款</span>
    {{#  } }}
</script>
<script type="text/html" id="purchaseTpl">
    {{#  if(d.id !=null){ }}
        {{#  if(d.lanunch === 1){ }}
            <a class="layui-btn layui-btn-xs" lay-event="checksource">查看</a>
        {{#  } else { }}
        <span>赠送生意</span>
        {{#  } }}
    {{#  } }}
</script>
<script>
    layui.use(['form', 'table', 'laydate'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table,
            laydate = layui.laydate;
        /*用户卡券*/
        table.render({
            elem: '#currentTableId',
            url: '/admin/Member/businessInfo',
            method: 'post',
            where: {memberCode: "{$memberCode}"},
            parseData: function (res) { //res 即为原始返回的数据
                $('#memberCode').val(res.data.info.code);
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.msg, //解析提示文本
                    "count": res.data.info.total, //解析数据长度
                    "data": res.data.info.data, //解析数据列表
                };
            },
            toolbar: '#toolbarDemo',
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            cols: [[
                {field: 'grid', title: '栏位号', sort: true, align: 'center' ,width:100},
                {field: 'status', title: '当前状态', align: 'center', templet: '#statusTpl',width:100},
                {field: 'industry_title', title: '生意名称', sort: true, align: 'center' ,width:130},
                { title: '购买途径', sort: true, align: 'center',templet: '#purchaseTpl'},
                {field: 'buy_time', title: '购买日期', sort: true, align: 'center'},
                {field: 'buy_price', title: '购买金额', sort: true, align: 'center'},
                {field: 'growth_cycle', title: '生长周期', sort: true, align: 'center'},
                {field: 'earnings_ratio', title: '收益比例', sort: true, align: 'center'},
                {field: 'earnings_price', title: '周期收益', sort: true, align: 'center'},
                {field: 'sale_price', title: '出售金额', sort: true, align: 'center'},
                {field: 'sell_time', title: '可出售日期', sort: true, align: 'center'},
                {title: '操作', toolbar: '#currentTableBar'}
            ]],
            limits: [12, 15, 20, 25, 30, 50, 100],
            limit: 12,
            page: true,

            done: function (res, curr, count) {

            }
        });

        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            var result = JSON.stringify(data.field);
            //执行搜索重载
            table.reload('currentTableId', {
                page: {
                    curr: 1
                }
                , where: {
                    searchParams: result
                }
            }, 'data');
            return false;
        });
        // 监听搜索操作
        form.on('select(status)', function(data){
            table.reload('currentTableId', {
                page: {
                    curr: 1
                }
                , where: {
                    status:data.value
                }
            }, 'data');
            return false;
        });
        /*赠送*/
        table.on('toolbar(currentTableFilter)', function (obj) {
            if (obj.event === 'add') {  // 监听添加操作
                var index = layer.open({
                    title: '赠送',
                    type: 2,
                    shade: 0.2,
                    maxmin: true,
                    shadeClose: true,
                    area: ['100%', '100%'],
                    content: "/admin/Member/giveBusiness?action=view&code={$memberCode}",
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
            }else if(obj.event=='warelist'){
                layer.open({
                    type: 2,
                    title: "仓库生意列表",
                    shadeClose: true,
                    shade: 0.5,
                    area: ['100%', '100%'],
                    content: '/admin/Member/memberInfo?view=wareInfo&memberCode=' + "{$memberCode}"
                });
            }
        });
        /*删除*/
        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            if (obj.event === 'delete') {
                layer.confirm('真的删除么', function (index) {
                    $.ajax({
                        url: '/admin/Member/businessInfo?action=delete',
                        type: 'post',
                        dataType: 'json',
                        data: {id:data.id},
                        success: function (res) {
                            if (res.status == true) {
                                // 关闭弹出层
                                obj.del();
                                layer.close(index);
                            } else {
                                layer.close(index);
                                layer.msg(res.msg);
                            }
                        },
                        error: function () {
                            layer.msg("报错了");
                        }
                    });
                });
            }else if(obj.event === 'confimTrade'){
                layer.confirm('确认交易吗？', function (index) {
                    $.ajax({
                        url: '/admin/Member/businessInfo?action=confimTrade',
                        type: 'post',
                        dataType: 'json',
                        data: {id:data.id},
                        success: function (res) {
                            if (res.status == true) {
                                // 关闭弹出层
                                layer.close(index);
                                table.reload('currentTableId', {
                                    page: {
                                        curr: 1
                                    }
                                    , where: {
                                        searchParams: data.field
                                    }
                                }, 'data');
                            } else {
                                layer.close(index);
                                layer.msg(res.msg);
                            }
                        },
                        error: function () {
                            layer.msg("报错了");
                        }
                    });
                });
            }else if(obj.event=='checksource')
            {
                var index = layer.open({
                    title: '交易记录',
                    type: 2,
                    shade: 0.2,
                    maxmin: true,
                    shadeClose: true,
                    area: ['100%', '100%'],
                    content: "/admin/PlatformData/tradAudit?action=view&source=1&business_id="+data.id+"&buy_code="+data.member_code,
                });
            }
        });

    });
</script>

</body>
</html>